<?php

/***
 *分布式部署
 *需就把其他的注释掉
 **/
ini_set('display_errors', 'off');
error_reporting(0);
use Workerman\Worker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use GatewayWorker\BusinessWorker;


//===================register========================
$register       = new Register('text://0.0.0.0:3050');
$register->name = 'RegisterWorker';



//===================business========================
$worker = new BusinessWorker();
$worker->name = 'BusinessWorker';
$worker->count = 12;
$worker->registerAddress = '0.0.0.0:3050';



//===================gateway========================
$gateway = new Gateway("websocket://0.0.0.0:30001");
$gateway->name = 'GatewayWorker';
$gateway->count = 12;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = '30002';
$gateway->registerAddress = '0.0.0.0:3050';
$gateway->pingInterval = 10;
$gateway->pingData = '{"type":"ping"}';
GatewayWorker\Lib\Gateway::$registerAddress = '127.0.0.1:3050';

/*
// 当客户端连接上来时，设置连接的onWebSocketConnect，即在websocket握手时的回调
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
        // 可以在这里判断连接来源是否合法，不合法就关掉连接
        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
        if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
        {
            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);
    };
};
*/



// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}